<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <meta name="renderer" content="webkit|ie-comp|ie-stand">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
  <meta http-equiv="Cache-Control" content="no-siteapp" />
  <title>现货表</title>
</head>

<body>
  <div id="app" v-loading.fullscreen.lock="loading">
    <div class="spot-material">
      <search-btn-view btn-text="查询现货" @before-open="resetSearch" @search="searchData">
        <div slot="search-content">
          <search-form is-customer :search="search"></search-form>
        </div>
      </search-btn-view>
      <div class="spot-material-table-div">
        <el-table fit stripe border highlight-current-row :data="materialList" style="width: 100%" height="parent">
          <el-table-column prop="materialName" label="产品名称" min-width="120px" header-align="center"></el-table-column>
          <el-table-column prop="model" label="规格" min-width="120px" header-align="center"></el-table-column>
          <el-table-column prop="color" label="编号" min-width="100px" header-align="center"></el-table-column>
          <el-table-column prop="colorDescription" label="描述" min-width="120px" header-align="center"></el-table-column>
          <el-table-column prop="material" label="材质" min-width="120px" header-align="center"></el-table-column>
          <el-table-column prop="materialDeptName" label="产品部门" min-width="100px" align="center"></el-table-column>
          <el-table-column prop="providerNo" label="供方编号" min-width="120px" header-align="center"></el-table-column>
          <el-table-column prop="count" label="库存" min-width="80px" align="center"></el-table-column>
          <el-table-column prop="unit" label="单位" min-width="80px" align="center"></el-table-column>
          <el-table-column prop="unitPrice" label="单价" min-width="80px" align="center"></el-table-column>
          <el-table-column :resizable="false" fixed="right" label="操作" width="80px" align="center">
            <template slot-scope="scope">
              <el-button size="mini" type="primary" @click="lookDetail(scope.row)">详情</el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>

      <table-pagination v-if="pagination.totalCount!==0" :page-sizes="[10,15,20,40,50]" :pagination="pagination" @change="pageChange">
      </table-pagination>
    </div>

    <el-dialog title="现货详情" :visible.sync="openDetailDialog" top="5vh" @closed="selectMaterial=null">
      <div style="height: calc(85vh - 54px); overflow: auto">
        <material-detail is-customer v-if="openDetailDialog" :material="selectMaterial"></material-detail>
      </div>
    </el-dialog>
  </div>
</body>

<script src="../../myJs/importFile.js"></script>
<script>
  importFile([
    "/vueSystem/components/css/sysCommonSearch.css",
    "/vueSystem/components/css/searchBtnView.css",
    "/vueSystem/components/css/imgUpload.css",
    "./css/materialForm.css"
  ], [
    "/vueSystem/i18n/index.js",
    "/vueSystem/components/sysCommonSearch.js",
    "/vueSystem/components/searchBtnView.js",
    "/vueSystem/models/baseModel.js",
    "/vueSystem/components/imgUpload.js",
    "/vueSystem/mixins/tablePaginationMixin.js"
  ]);

</script>
<script src="../models/spotMaterialModel.js"></script>
<script src="./searchForm.js"></script>
<script src="./materialDetail.js"></script>

<script>
  var app = new Vue({
    el: '#app',
    mixins: [
      tablePaginationMixin(15)
    ],

    data: function () {
      var search = {
        materialName: '',
        model: '',
        color: '',
        providerName: '',
        providerNo: '',
        colorDescription: '',
        defaultWarehouse: '原材料仓',
        status: 1,
        materialDept: ''
      };
      return {
        loading: false,
        materialList: [],
        search: _.cloneDeep(search),
        oldSearch: _.cloneDeep(search),
        openDetailDialog: false,
        selectMaterial: null
      };
    },

    created: function () {
      this.setMaterialList(true);
    },

    methods: {
      setMaterialList: function (isSearch) {
        if (!isSearch) {
          this.search = _.cloneDeep(this.oldSearch);
        }

        var search = this.search;
        var pagination = this.pagination;
        var currentPage = pagination.currentPage;
        var pageSize = pagination.pageSize;
        var start = (currentPage - 1) * pageSize;
        var postData = {
          start: start,
          length: pageSize,
          view: search.status,
          providerNo: search.providerNo,
          isSpot: 1
        };
        var fields = ['materialName', 'model', 'color', 'colorDescription', 'providerName', 'defaultWarehouse'];
        SysUtil.setPostData(postData, search, fields);

        var materialDept = search.materialDept;
        if (materialDept !== '') {
          postData.materialDeptId = materialDept.materialDeptId;
        }

        this.loading = true;
        var self = this;
        return ajaxRequest("thirdPartyView/queryMaterialCompany", postData, true).then(function (res) {
          if (isSearch) {
            self.oldSearch = _.cloneDeep(self.search);
          }

          var materialList = res.returnData;
          for (var i = 0; i < materialList.length; i++) {
            var material = materialList[i];
            var materialDeptId = material.materialDeptId;
            if (SysUtil.isEmpty(materialDeptId) || materialDeptId === 0) {
              materialDeptId = '';
            }
            var materialDeptName = material.materialDeptName;
            if (SysUtil.isEmpty(materialDeptName)) {
              materialDeptName = '';
            }
            material.materialDeptId = materialDeptId;
            material.materialDeptName = materialDeptName;
          }

          self.materialList = materialList;
          self.pagination.totalCount = res.iTotalRecords;
          self.loading = false;
        }).catch(function () {
          self.loading = false;
        });
      },

      resetSearch: function () {
        this.search = _.cloneDeep(this.oldSearch);
      },

      searchData: function () {
        this.pagination.currentPage = 1;
        this.setMaterialList(true);
      },

      pageChange: function () {
        this.setMaterialList();
      },

      lookDetail: function (material) {
        this.selectMaterial = material;
        this.openDetailDialog = true;
      }
    },

    components: {
      SearchBtnView: SearchBtnView,
      SearchForm: SearchForm,
      MaterialDetail: MaterialDetail
    }
  });

</script>
<style>
  .spot-material {
    padding: 10px 20px 5px;
    height: calc(100% - 15px);
    overflow: auto;
    display: flex;
    flex-direction: column;
  }

  .spot-material .spot-material-table-div {
    flex: 1;
    overflow: auto;
  }

</style>

</html>
